﻿package model.utils
{
	import flash.display.Stage;
	/**
	 * ...
	 * @author Lobanov AV.
	 */
	public class ModuleConfig 
	{
		// default domain
		public static var DOMAIN:String = "http://katnikova"
		public static var DEFAULT_SITE_PATH:String = "";
		public static var CORE_DATAS_PATH:String = "http://katnikova/core/";
		
		// assocc array
		private var modulFullpath:Object;
		private var _domain:String;
		
		// * singletone propertys
		public static var instance:ModuleConfig;
		private static var allowInstantiation:Boolean;
		
		/**
		 * Singletone
		 * @return
		 */
		public static function getInstance():ModuleConfig {		
			if (instance == null) {			
				allowInstantiation = true;
				instance = new ModuleConfig();
				allowInstantiation = false;
			}
			return instance;
        }
		
	    public function ModuleConfig():void {
			if (!allowInstantiation) {
				throw new Error("Error: Instantiation failed: Use ModuleConfig.getInstance() instead of new.");
			}
        }
		
		/**
		 * init Fullpath array
		 * 
		 * 1. catalog
		 * 2. dillers
		 * 3. news`	
		 * 4. search
		 * 5. sitemal
		 * 6. stock
		 * 
		 * @param	data xml
		 */
		public function initFullpath(data:XML):void {		
			modulFullpath = new Object();
			
			for each (var modul:XML in data.modules.item) 
			{
				modulFullpath[modul.@name] = modul.@fullpath;
			}
		}
		
		//-------------------------------
		// Setter mthods
		//-------------------------------
		public function set domain(s:String):void {
			for (var inc:uint = 0; inc < acccess_domain.length; inc++ ) {
				if (acccess_domain[inc] == s) {
					_domain = "" + s;
					return ;
				}
			}
			_domain = "" + DEFAULT_SITE_PATH;
		}
		
		//-------------------------------
		// Getter method
		//-------------------------------
		public function get domain():String {
			return _domain;
		}
		
		/**
		 * @param modName 
		 * @return fullpath for target modul
		 */
		public function retriveModFullpath(modName:String):String {
			return modulFullpath[modName];
		}
	}
}